<?php
/**
 * @企业类类
 * 1、企业list
 * 2、注册
 * 3、忘记密码
 * 4、修改资料 
 * @作者 
 * 万全强（php）
 */
namespace app\controller;

use app\controller\HomeBase;
use think\facade\Db;

use app\model\ParkModel;
use app\model\Chain;





class Park extends HomeBase
{
    private $ParkModel;
    private $ChainModel;

    public function __construct(){
               
        parent::__construct();
        $this->ParkModel=new  ParkModel();
        $this->ChainModel=new Chain();

    }
    public function GetList(){
        $where="  a.status=1  ";

    	$field="a.id,park_name,identification,thumb,city,prime_mover_industry,park_introduction,level,park_area,land_price,address,phone,a.code";

        $condition=[];

       /***关键字*/
    	$keywords=request()->param('keywords','','trim');
    	if(!empty($keywords)){
            $condition['keywords']=$keywords;
    	}
       /***行业*/
    	$industry_id=request()->param('industry_id',0,'intval');
    	if(!empty($industry_id)){
            $condition['industry_id']=$industry_id;
    	}
         /***产业链*/
    	$chain_id=request()->param('chain_id',0,'intval');
    	if(!empty($chain_id)){
            $condition['chain_id']=$chain_id;
    	}
    
        /***城市*/
    	$city_id=request()->param('city_id',0,'intval');
    	if(!empty($city_id)){
            $condition['city_id']=$city_id;
        }
        
        $listobj=$this->ParkModel->GetList($field,$condition);
      
        
        $searchParams['index'] = config('app.elasticsearch')['CompanyIndex'];
    	$searchParams['type'] = config('app.elasticsearch')['type'];
        if($listobj['data']){
            foreach ($listobj['data'] as $key => &$value) {
               
                /**
                 * 企业个数
                 */
                $searchParams['body']['query']['bool']['must']=[];
                $searchParams['body']['query']['bool']['should']=[];

                $searchParams['body']['query']['bool']['must'][]=array('term' => array('park_id' => $value['id']));

                $retDoc = $this->client->count($searchParams);
                //$retDoc = $this->client->search($searchParams);
                $value['CompanyNum']=$retDoc['count'];
            }
        }

        return json(['status'=>1,'msg'=>'获取成功','data'=>$listobj]);
    }
    public  function GetParkTotal(){
    	
    	$condition=[];
    	if($this->user_id){
    		$condition['user_id']=$this->user_id;
    	}
    	
    	$keywords = request()->param('keywords', '', 'trim');
    	$keywords=preg_replace("/\\d+/",'', trim($keywords));
    	if($keywords){
    		$condition['keywords']=$keywords;
    	}
    	//地方
    	$chain_id = request()->param('chain_id', 0, 'intval');
    	if (!empty($chain_id)) {
    		$condition['chain_id']=$chain_id;
    	}
    	//云端
    	$yun_chain_id = request()->param('yun_chain_id', 0, 'intval');
    	if (!empty($yun_chain_id)) {
    		$condition['yun_chain_id']=$yun_chain_id;
    	}
    	
    	$city_id = request()->param('city_id', 0, 'intval');
    	if (!empty($city_id)) {
    		$condition['city_id']=$city_id;
    	}
    	
    	$industry_id = request()->param('industry_id', 0, 'intval');
    	if (!empty($industry_id)) {
    		$condition['industry_id']=$industry_id;
    	}
    	
    	$total=$this->ParkModel->GetTotal($condition);
    	return json(['status'=>1,'msg'=>'获取成功','data'=>$total]);
    }
    
}